home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / basdir.arc / FCBREAD.BAS (.txt) < prev    next >
Encoding:
GW-BASIC  |  1985-11-01  |  3.5 KB  |  68 lines

  1. 10  ' COPYRIGHT @ 1983
  2. 20  '    Jim Holtman
  3. 30  '    35 Dogwood Trail
  4. 40  '    Randolph, NJ 07869
  5. 50  '    (201) 361-3395
  6. 60  '   This sample program serves as both an example and the documentation
  7. 70  '   for the FCBREAD.BSV routine that will read the directory of a
  8. 80  '   disk and present the matching file name back to the BASIC program.
  9. 90  '   Also available to the program is the directory information that
  10. 100  '   contains the size and time/date information. This routine is
  11. 110  '   faster than OPENing the file since it does not incur that overhead.
  12. 120  '   Also the user can present an arbitrary string to match on.
  13. 130  '
  14. 140  '   To use, BLOAD the routine into any available free memory. It
  15. 150  '   has 2 entry points (INIT and GETNEXT). INIT (offset 2) is used
  16. 160  '   to define the disk drive (0=default, 1=A, 2=B, ....) and the
  17. 170  '   pattern to be used to match on. The pattern MUST BE a string of
  18. 180  '   length 11; the first 8 are the filename and the last 3 are the
  19. 190  '   extension. A "?" is used to match any character. For example to
  20. 200  '   get all the BASIC files on the disk, "????????BAS" would be used
  21. 210  '   as the input parameter. After INIT has been called, calls to
  22. 220  '   GETNEXT (offset 5) are made to retrieve matching file names.
  23. 230  '   The two parameters are the string in which the match is returned
  24. 240  '   (which must be of length 14) and an INTEGER (..%) return value.
  25. 250  '   If the status return is <0, no more matched have been found. If
  26. 260  '   status >=0, it is the FILE ATTRIBUTE (as defined in the DOS Disk
  27. 270  '   Directory).
  28. 280  '
  29. 290  '   A third entry point (CHMOD, offset 8) is provided to change the
  30. 300  '   file 'mode' bit. Three parameters are required; file name, new
  31. 310  '   mode (INTEGER) and status return (INTEGER).
  32. 320  '
  33. 330  '   The INTEGER value at offsets 0,1 in the routine are the offset
  34. 340  '   to the directory entry for the file. For example, to obtain the
  35. 350  '   DATE information of the file, use the following statements:
  36. 360  '        B% = PEEK(bload.base)+PEEK(bload.base+1)*256+BLOAD.BASE   ' Get offset value
  37. 370  '        FDATE = PEEK(B%+26)*256 + PEEK(B%+25)
  38. 380  '
  39. 390  '   The offsets into the directory entry (25, 26 in this case) are
  40. 400  '   defined in the DOS manual.
  41. 410  '
  42. 420  '   The example program will list all the files on the default disk.
  43. 430  '   It will traverse all the directories on the disk and list the file
  44. 440  '   name and its attributes in HEX.
  45. 450  CLEAR ,&HF000  'setup area into which FCBREAD.BSV will be loaded
  46. 460  BLOAD.BASE=&HF000
  47. 470  BLOAD "fcbread.bsv",BLOAD.BASE  'load into area CLEARed by CLEAR command
  48. 480  INIT%=BLOAD.BASE+2:GETNEXT%=BLOAD.BASE+5  'entry point offsets take into account the base of BLOAD.
  49. 490  IMAX%=30:INEXT%=1
  50. 500  DIM DIR$(IMAX%)
  51. 510  CLS
  52. 520  CHDIR "\"            'start at the ROOT
  53. 530  CUR$=""
  54. 540  PAT$="???????????"  'match any file
  55. 550  DISK%=0:CALL INIT%(DISK%,PAT$)
  56. 560  FILENAME$=SPACE$(14):CALL GETNEXT%(FILENAME$,STATUS%)
  57. 570  IF STATUS%<0 THEN IF INEXT%>1 THEN INEXT%=INEXT%-1:CUR$=DIR$(INEXT%):CHDIR CUR$:GOTO 550 ELSE END
  58. 580  DISK$=LEFT$(FILENAME$,2):FILENAME$=MID$(FILENAME$,3)
  59. 590  IF (STATUS% AND &H10)=0 THEN GOTO 660   ' check for DIRECTORY
  60. 600  IF LEFT$(FILENAME$,1)="." THEN GOTO 560      'ignore "." entries
  61. 610  FILENAME$=LEFT$(FILENAME$,INSTR(FILENAME$,".")-1)
  62. 620  IF INEXT%>IMAX% THEN PRINT "Directory Stack Overflow":GOTO 560
  63. 630  DIR$(INEXT%)=CUR$+"\"+FILENAME$
  64. 640  INEXT%=INEXT%+1
  65. 650  GOTO 560
  66. 660  PRINT "x'"+HEX$(STATUS%)+"'" TAB(8) CUR$ "\" FILENAME$
  67. 670  GOTO 560
  68.